﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);
}

MainWindow::~MainWindow() { delete ui; }

void MainWindow::mousePressEvent(QMouseEvent *ev) {
  if (ui->screen_2->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
    mouseFromWhere = 2;
    qDebug() << "mouseFrom2";
  }
  if (ui->screen_3->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
    mouseFromWhere = 3;
    qDebug() << "mouseFrom3";
  }
  if (ui->screen_4->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
    mouseFromWhere = 4;
    qDebug() << "mouseFrom4";
  }
  if (ui->screen_5->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
    mouseFromWhere = 5;
    qDebug() << "mouseFrom5";
  }
}

void MainWindow::mouseReleaseEvent(QMouseEvent *ev) {
  if (ui->screen_1->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
    qDebug() << "mouseAt1";
    switch (mouseFromWhere) {
    // 切换至画面1
    case 2:
      ui->screen_1->setStyleSheet("border-image: url(:/image/2.png)");
      ui->comboBox->setCurrentIndex(0);
      mouseFromWhere = 0;
      break;
    // 切换至画面2
    case 3:
      ui->screen_1->setStyleSheet("border-image: url(:/image/3.png)");
      ui->comboBox->setCurrentIndex(1);
      mouseFromWhere = 0;
      break;
    // 切换至画面3
    case 4:
      ui->screen_1->setStyleSheet("border-image: url(:/image/4.png)");
      ui->comboBox->setCurrentIndex(2);
      mouseFromWhere = 0;
      break;
    // 切换至画面4
    case 5:
      ui->screen_1->setStyleSheet("border-image: url(:/image/5.png)");
      ui->comboBox->setCurrentIndex(3);
      mouseFromWhere = 0;
      break;
    default:
      break;
    }
  }
}

void MainWindow::on_comboBox_activated(int index)
{
    switch(index){
    // 切换至画面1
    case 0:
      ui->screen_1->setStyleSheet("border-image: url(:/image/2.png)");
      break;
    // 切换至画面2
    case 1:
      ui->screen_1->setStyleSheet("border-image: url(:/image/3.png)");
      break;
    // 切换至画面3
    case 2:
      ui->screen_1->setStyleSheet("border-image: url(:/image/4.png)");
      break;
    // 切换至画面4
    case 3:
      ui->screen_1->setStyleSheet("border-image: url(:/image/5.png)");
      break;
    default:
      break;
    }
}

